import 'package:flutter/material.dart';

/// 闪屏 启动图
class FlashScreenPage extends StatefulWidget {
  final Map<String, dynamic> arguments;

  /// 动画结束回调
  final VoidCallback completion;

  FlashScreenPage({Key key, this.arguments, @required this.completion}) : super(key: key);

  @override
  _FlashScreenPageState createState() => _FlashScreenPageState();
}

class _FlashScreenPageState extends State<FlashScreenPage> with SingleTickerProviderStateMixin {
  AnimationController _animationController;
  Animation _animation;

  @override
  void initState() {
    super.initState();

    _animationController = AnimationController(vsync: this, duration: Duration(milliseconds: 600));
    _animation = Tween(begin: 1.0, end: 0.0).animate(_animationController);

    _animation.addStatusListener((status) {
      if (status == AnimationStatus.completed) {
        widget.completion();
      }
    });

    //
    Future.delayed(Duration(seconds: 2)).then((value) {
      _animationController.forward();
    });
  }

  @override
  void dispose() {
    _animationController.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return FadeTransition(
      opacity: _animation,
      child: Container(
        color: Color.fromARGB((255.0 * _animation.value).toInt(), 255, 255, 255),
        child: Image.asset('resources/images/others/flash_screen.jpg', scale: 2.0, fit: BoxFit.cover),
      ),
    );
  }
}
